import { http } from "@/utils/http";
import type { DaemonSet, DaemonSetList } from "./types";
import type { BaseResponse } from "@/api/response";
import {
  k8sPathMergeReqs,
  type MakePathReq,
  type MergePathReq
} from "./apiHelper";

export class K8sDaemonSet {
  baseReq: MakePathReq = {
    src: "daemonsets",
    app: "apps/v1"
  };

  newEntity = (): DaemonSet => ({
    apiVersion: this.baseReq.app,
    kind: "DaemonSet",
    metadata: {
      name: "",
      namespace: "",
      labels: {},
      annotations: {}
    },
    spec: {}
  });

  getDaemonSet = (req: MergePathReq): BaseResponse<DaemonSetList> => {
    const api = k8sPathMergeReqs(req, this.baseReq);

    return http.get(api, { params: req.query });
  };

  getDaemonSetDetail = (
    req: MergePathReq,
    data?: DaemonSet
  ): BaseResponse<DaemonSet> => {
    const api = k8sPathMergeReqs(req, this.baseReq, data);

    return http.get(api);
  };

  createDaemonSet = (data: DaemonSet): BaseResponse => {
    const api = k8sPathMergeReqs(this.baseReq, data);

    return http.post(api, { data });
  };

  updateDaemonSet = (req?: MergePathReq, data?: DaemonSet): BaseResponse => {
    const api = k8sPathMergeReqs(req, this.baseReq, data);

    return http.put(api, { data });
  };

  patchDaemonSet = (req: MergePathReq, data: DaemonSet): BaseResponse => {
    const api = k8sPathMergeReqs(req, this.baseReq, data);
    return http.patch(api, { data });
  };

  deleteDaemonSet = (req?: MergePathReq, data?: DaemonSet): BaseResponse => {
    const api = k8sPathMergeReqs(req, this.baseReq, data);
    return http.delete(api, { data });
  };
}
